package bishi强训;
import java.util.*;

import java.io.*;

public class Test2 {

        //笔试强训 day17第二题  十字爆破   要用IO流输入
        public static Read in = new Read();
    public static PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
    public static void main(String[] args) throws IOException {
        int n = in.nextInt();
        int m = in.nextInt();
        //预处理两个数组  一个记录纵坐标  一个记录横坐标
        long[][] arr = new long[n][m];
        long[] row = new long[n]; //横坐标
        long[] col = new long[m]; //纵坐标

        for(int i = 0; i < n; i++) {
            for(int j = 0; j < m;j++) {
                arr[i][j] = in.nextLong();
                row[i] += arr[i][j];
                col[j] += arr[i][j];
            }
        }

        //使用 输出
        for(int i = 0; i < n; i++) {
            for(int j = 0; j< m;j++) {
                out.print(row[i] + col[j] - arr[i][j] + " ");
            }
            out.println();  //换行
        }

        out.close();
    }
}

class Read
{
    StringTokenizer st = new StringTokenizer("");
    BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
    String next() throws IOException
    {
        while(!st.hasMoreTokens())
        {
            st = new StringTokenizer(bf.readLine());
        }
        return st.nextToken();
    }

    String nextLine() throws IOException
    {
        return bf.readLine();
    }

    int nextInt() throws IOException
    {
        return Integer.parseInt(next());
    }

    long nextLong() throws IOException
    {
        return Long.parseLong(next());
    }

    double nextDouble() throws IOException
    {
        return Double.parseDouble(next());
    }
}
